import { html, pinyin } from "pinyin-pro";

/**
 * 获取拼音
 * 参考 https://pinyin-pro.cn/use/html.html
 */
const getPinyinList = (message: string) => {
  const pinyinList: Array<string> = pinyin(message, { type: "array" });
  return pinyinList;
};

const getPinyinHtml = (message: string) => {
  return html(message);
};

/**
 * 测试一句诗词
 */
const getOnePoet = (): Promise<string> => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(
        "泉眼无声惜细流，树阴照水爱晴柔。\n" +
          "小荷才露尖尖角，早有蜻蜓立上头。",
      );
    }, 1000);
  });
};

const fetchChatByGet = (question: string = "你好") => {
  const params = new URLSearchParams();
  params.append("question", question);
  return fetch("http://127.0.0.1:8001/chat?" + params.toString(), {
    method: "GET",
  });
};

export { getOnePoet, getPinyinList, getPinyinHtml, fetchChatByGet };
